perm filename CHESS.DOC[4,KMC] blob
sn#177286 filedate 1975-09-17 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00003 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 CS 105/106 out: May 14, 1975
C00006 00003 SELECTING A MOVE FOR WHITE: STRATEGY
C00009 ENDMK
C⊗;
CS 105/106 out: May 14, 1975
PROJECT due in 106: June 4, 1975
due in 105: June 9, 1975
ROOK & KING END GAME:
Develop a program which plays the white pieces in a chess
game, with a white king and rook against a black king. We will
provide you with a procedure with the declaration
"PROCEDURE BKMOVE(INTEGER VALUE OBKX, OBKY, OWKX, OWKY, OWRX, OWRY;
INTEGER RESULT NBKX, NBKY);"
which accepts the cartesian coordinates of the 3 pieces (in the range
1 to 8) and yields the new coordinates to which the black king moves,
with zeroes if black has no legal move. BKMOVE will also return
zeroes if an illegal position is given to it. You should put the
cards we provide at the front of your program, just after the initial
BEGIN.
We will also provide data cards with several legal sets of
initial coordinates (white to move), in the same order as the
procedure inputs. You should "READON(BKX, BKY, WKX, WKY, WRX, WRY);".
Your program should terminate when it reads BKX = 0.
Upon reading each starting position, your program should play
a game of chess against the BKMOVE procedure. In each turn, you
should select a legal move for one of the white pieces and alter its
coordinates to reflect the move. Then call BKMOVE. The BKMOVE
procedure will observe the present coordinates of each piece and
return new coordinates for the black king. It will also print a
picture of the board before and after it moves the black king. Your
program thus should call it only when it has decided what move it
wants to make.
OUTLINE OF PROGRAM STRUCTURE:
This is the ALGOLW translation of the description given above.
BEGIN
COMMENT The following declaration will be provided on cards in 181 Pine;
{{ PROCEDURE BKMOVE(INTEGER VALUE OBKX, OBKY, OWKX, OWKY, OWRX, OWRY;
INTEGER RESULT NBKX, NBKY);
A rather obscure procedure body will follow. }}
READON(BKX, BKY, WKX, WKY, WRX, WRY);
COMMENT This loop terminates on a data card giving BKX = 0;
WHILE (BKX ≠ 0) DO
BEGIN
COMMENT This loop terminates when BKMOVE returns a new BKX = 0;
WHILE (BKX ≠ 0) DO
BEGIN
{{ You select and make a move for white. }}
BKMOVE(BKX, BKY, WKX, WKY, WRX, WRY, BKX, BKY)
END;
READON(BKX, BKY, WKX, WKY, WRX, WRY)
END
END.
SELECTING A MOVE FOR WHITE: STRATEGY
In selecting a move for white, your program should consider
some of the following objectives:
1) Make only legal moves. (Don't move off the board, etc.)
2) Don't lose the rook.
3) Don't allow a stalemate.
4) Checkmate the black king.
5) Checkmate the black king in less than 20 moves.
Partial credit will be given for completing parts 1 & 2 (above). For
substantial credit, it is necessary to achieve part 3 also. Once you
have done this you may make the obvious improvements.
RULES OF PLAY:
If you don't already know these, you probably shouldn't do
this project.
1) A king at (KX, KY) ATTACKS all squares (X, Y) such that |X-KX|≤1 ,
|Y-KY|≤1 , and (X, Y) ≠ (KX, KY).
2) A rook ATTACKS all squares (except the one it occupies) in a
vertical or horizontal direction with no intervening pieces.
3) A king MOVES to any square attacked by it, not occupied by a
friendly piece, and not attacked by a hostile piece.
4) A rook MOVES to any square attacked by it and not occupied by a
friendly piece.
5) If a king is on a square attacked by a hostile piece, it is in
CHECK.
6) If a king is in check and has no legal move, it is CHECKMATED, and
loses the game.
7) If a player, whose turn it is to move, is not in check, but has no
legal move for any of his pieces, he is STALEMATED, and the game is a
draw.
8) If only kings remain on the board, the game is a draw.
9) The players alternate making a move until a won or drawn position
is reached.
10) The above rules, while correct and sufficient for a king and rook
against a king, are false and inadequate for chess in general.